/*
package com.snap.vseries.fragment.cit;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.TextView;


import com.snap.vseries.R;
import com.snap.vseries.base.CitFragment;
import com.snap.vseries.bean.TestItem;
import com.snap.vseries.dialog.NumberInputDialog;
import com.snap.vseries.framework.MoleExecutor;
import com.snap.vseries.framework.MoleTask;
import com.snap.vseries.serial.Cmd;
import com.snap.vseries.ui.widget.TextButton;
import com.snap.vseries.utils.ToastUtils;

import java.io.IOException;
import java.util.concurrent.Future;

import butterknife.BindView;



@SuppressLint("ValidFragment")
public class LightStabilityFragment extends CitFragment {

    public static final int DEF_FAM = 10000;
    public static final int DEF_VIC = 10000;
    public static final int DEF_ROX = 10000;
    public static final int DEF_CY5 = 10000;

    @BindView(R.id.fam_et)
    TextView famEt;
    @BindView(R.id.vic_et)
    TextView vicEt;
    @BindView(R.id.rox_et)
    TextView roxEt;
    @BindView(R.id.cy5_et)
    TextView cy5Et;

    @BindView(R.id.result_label)
    TextView resultLabel;
    @BindView(R.id.result_tv)
    TextView resultTv;
    @BindView(R.id.start_btn)
    TextButton startBtn;

    private TestItem testItem;
    private final int position;

    private int[] targets = new int[4];
    private Future future;
    private long cancelClickTime;

    public LightStabilityFragment(int position, TestItem testItem) {
        this.position = position;
        this.testItem = testItem;
    }

    @Override
    protected int layoutResId() {
        return R.layout.fragment_cit_light_stability;
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        targets[0] = DEF_FAM;
        targets[1] = DEF_VIC;
        targets[2] = DEF_ROX;
        targets[3] = DEF_CY5;
        TextView[] tvs = {famEt, vicEt, roxEt, cy5Et};
        for (int i = 0; i < tvs.length; i++) {
            int target = targets[i];
            final int index = i;
            tvs[i].setText(String.valueOf(target));
            tvs[i].setOnClickListener(v ->
                    new NumberInputDialog().setParam(0, 1, target, 50000, "目标值", "", value -> {
                        targets[index] = (int) value;
                        tvs[index].setText(String.valueOf(targets[index]));
                    }).show(getChildFragmentManager(), ""));
        }
        startBtn.setOnClickListener(v -> {
            if (!isTesting()) {
                setTesing(true);
                startBtn.setText("测试中...(双击取消测试)");
                startBtn.setBackgroundResource(R.drawable.btn_cit_running);
                resultLabel.setVisibility(View.GONE);
                resultTv.setText("");
                future = MoleExecutor.getInstance().execute(new MoleTask<Boolean>() {
                    @Override
                    public Boolean runInBackground() throws InterruptedException {
                        try {
                            getSerialPortHelper().open();
                            Bundle bundle = getSerialPortHelper().execute(Cmd.ledStability(DEVICE_TYPE, LIGHTING_MODULE_INDEX, 1));
                            if (bundle.getBoolean("suc")) {
                                Thread.sleep(1000);
                                bundle = getSerialPortHelper().execute(Cmd.ledStability(DEVICE_TYPE, LIGHTING_MODULE_INDEX, 2));
                                if (bundle.getBoolean("suc")) {
                                    byte[] data = bundle.getByteArray("data");
                                    int famValue = ((data[6] & 0xff) << 8) + (data[7] & 0xff);
                                    int vicValue = ((data[8] & 0xff) << 8) + (data[9] & 0xff);
                                    int roxValue = ((data[10] & 0xff) << 8) + (data[11] & 0xff);
                                    int cy5Value = ((data[12] & 0xff) << 8) + (data[13] & 0xff);
                                    resultTv.post(() -> resultTv.append(String.format("fam: %d , vic: %d , rox: %d , cy5: %d\n", famValue, vicValue, roxValue, cy5Value)));
                                    return true;
                                } else {
                                    resultTv.post(() -> resultTv.append("读取LED数据失败\n"));
                                    return false;
                                }
                            } else {
                                resultTv.post(() -> resultTv.append("打开LED失败\n"));
                                return false;
                            }
                        } catch (IOException e) {
                            e.printStackTrace();
                            return false;
                        } finally {
                            getSerialPortHelper().close();
                        }
                    }

                    @Override
                    public void onCompleted(Boolean result) {
                        if (result) {
                            testItem.setState(1);
                            testItem.setComment("通过");
                        } else {
                            testItem.setState(2);
                            testItem.setComment("失败");
                        }
                        setTesing(false);
                        startBtn.setText("开始测试");
                        startBtn.setBackgroundResource(R.drawable.btn_cit_start);
                        resultLabel.setVisibility(View.VISIBLE);
                        resultLabel.setBackgroundResource(testItem.getState() == 2 ? R.drawable.bg_red_4 : R.drawable.bg_blue6_4);
                        notifyItem(position);
                    }
                });
            } else {
                if ((System.currentTimeMillis() - cancelClickTime) > 2000) {
                    cancelClickTime = System.currentTimeMillis();
                } else {
                    if (future != null) future.cancel(true);
                    ToastUtils.get().showText("再次点击取消当前测试！");
                    setTesing(false);
                    startBtn.setText("开始测试");
                    startBtn.setBackgroundResource(R.drawable.btn_cit_start);
                    resultLabel.setVisibility(View.GONE);
                    resultTv.setText("");

                    testItem.setState(0);
                    testItem.setComment("");
                    notifyItem(position);
                }
            }
        });
    }
}*/
